#include "projectile.h"
#include "pfire.h"
#include <OgreEntity.h>
#include <cmath>
#include <stdio.h>
#include <OgreMath.h>
#include "OgreParticleSystem.h"
#include <OgreParticleEmitter.h>

PFire::PFire(World *world, int speed, int size, Ogre::Real angle): Projectile(world,speed,size,angle){

    Ogre::SceneManager *scene = world->getSceneManager();
    Ogre::ParticleSystem* projectile = scene->createParticleSystem(25);
    projectile->setKeepParticlesInLocalSpace(true);
    projectile->setMaterialName("Examples/FlarePointSprite");
    projectile->setDefaultDimensions(size, size);

    //create particle emitter
    Ogre::ParticleEmitter* emitter = projectile->addEmitter("Point");

    //set emitter properties
    emitter->setAngle(Ogre::Degree(0));
    emitter->setTimeToLive(3);
    emitter->setDuration(0.1);
    emitter->setEmissionRate(10);
    emitter->setParticleVelocity(0);
    emitter->setDirection(Ogre::Vector3::UNIT_Z);
    emitter->setColour(Ogre::ColourValue::White);
    emitter->setPosition(Ogre::Vector3(-20, 0, 60));

    //attach projectile particle to m_node
    m_node->createChildSceneNode(Ogre::Vector3(0, 6.5, -67))->attachObject(projectile);

    setDamage(5);
}

void PFire::setPosition(Ogre::Vector3 pos){
    m_node->setPosition(pos);
}

void PFire::move(float time){
    if(m_angle >= 0 || m_angle <= 360){
        m_node->setPosition(m_node->getPosition() + Ogre::Vector3(m_x*time,0,m_z*time));
    }
    else{
        m_node->setPosition(m_node->getPosition() + Ogre::Vector3(0,0,m_speed*time));
    }
}

void PFire::colide(AI *object){
    /*if(object->isNpc() != isNpc() && object->getType() != getType()){
        m_world->removeActor(this);
    }*/
}

void PFire::destroy(){
    m_node->removeAndDestroyAllChildren();
    m_node->getParent()->removeChild(m_node);
    delete m_node;
}
